<?php
/**
 * Created by PhpStorm.
 * User: adminyj
 * Date: 2019/2/21
 * Time: 23:41
 */

namespace app\admin\model;


use app\common\model\Modelbase;
use think\Db;

class Sendmsg extends Modelbase
{

    /**
     * 推送信息
     * */
    public function pushMsg()
    {

    }

    /**
     * 存入消息
     * @param $uid
     * @param $aid
     * @param $title
     * @return mixed
     * */
    public function saveMsg($uid,$aid,$title="您的申请有了新进度")
    {

        $where[] = ['id','=',$aid];
        $info = Db::view('help_list')
            ->where($where)
            ->field('buchong,msg_info')
            ->find();
        $httpType = is_https();

        if($httpType){
            $https = "https://";
        }else{
            $https = "http://";
        }

        $http = $_SERVER['SERVER_NAME'];
        if($info['buchong']){
            $arr = explode(',',$info['buchong']);
            $a = count($arr);
            $pic = Db::name('images')->where(['id' => $arr[$a-1]])->field('type,img')->find();
            if($pic['type'] == 5){
                $img = $https.$http."/upolods/images/helpArticle/".$pic['img'];
            }else{
                $img = $https.$http.$pic['img'];
            }
            $pic = $img;
        }else{
            $pic = "";
        }
        $data = [
            'uid' => $uid,
            'apply_id' => $aid,
            'title' => $title,
            'content' => $info['msg_info'],
            'create_time' => time(),
            'pic' => $pic
        ];

        $res = Db::name('send_msg')->insert($data);

        if($res){
            return true;
        }else{
            return false;
        }


    }

}